/**
* 用户管理  用户信息
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index/mainAdmin' }">主页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户信息</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.adminName" placeholder="输入用户名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>

    <!--列表-->
<!--原数据-->
    <el-table size="small" :data="userData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" sortable prop="uid" label="用户id" width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="userName" label="用户名" width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="password" label="密码" width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="age" label="年龄" width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="sex" label="性别" min-width="50">
      </el-table-column>
      <el-table-column align="center" sortable prop="email" label="邮件" min-width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="phone" label="手机号" width="120">
      </el-table-column>
      <el-table-column align="center" sortable prop="idCard" label="身份证号" width="200">
      </el-table-column>
    </el-table>


    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

  </div>
</template>

<script>
// 导入请求方法
import Pagination from '../../components/Paginayion'
export default {
  data() {
    return {
      loading: false, //是显示加载
      title: '用户信息',
      editFormVisible: false, //控制编辑页面显示与隐藏
      userData:[],
      // 请求数据参数
      formInline: {
        page: 1,
        limit: 10,
        adminName:'',
        userName:''
      },
      listData: [], //搜索数据
      // 选择数据
      selectdata: [],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },

  /**
   * 数据发生改变
   */
  watch: {},

  /**
   * 创建完毕
   */
  created() {
    this.getdata()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    getdata() {
      this.loading = true
      this.$axios
          .get(`http://localhost:9090/loan/user/getUserList`).then(
          response => {
            this.userData = response.data;
            this.listData = response.data;

            // 分页赋值
            this.pageparm.currentPage = this.formInline.page
            this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = this.userData.length
            this.loading = false
          }
      )
    },

    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    //搜索事件
    search() {
      if (this.formInline.adminName===''){
        this.userData=this.listData
      }else {
        this.userData=[]
        this.loading = true
        for (let i=0;i<this.listData.length;i++){
          if (this.listData[i].userName.indexOf(this.formInline.adminName)!=-1){
            // alert('收到了')
            // console.log(this.listData[i])
            this.userData.push(this.listData[i])
          }
        }
        this.loading = false
      }



    },


  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>


